<template>
  <div v-infinite-scroll="onLoadMore"
       infinite-scroll-disabled="busy"
       infinite-scroll-distance="distance"
       infinite-scroll-throttle-delay="delay">
    <slot></slot>
    <div style="height: 50px; text-align: center;" v-if="!busy">
      <a-spin>
        <a-icon slot="indicator" type="loading" style="font-size: 24px; color: #fff;" spin />
      </a-spin>
    </div>
  </div>
</template>

<script lang="ts">
  import { Component, Vue, Prop, Emit } from 'vue-property-decorator';

  @Component
  export default class InfiniteScrollComponent extends Vue {
    @Prop({ type: Boolean, required: false, default: true })
    readonly busy?: boolean;

    @Prop({ type: Number, required: false, default: 50 })
    readonly distance?: number;

    @Prop({ type: Number, required: false, default: 1000 })
    readonly delay?: number;

    @Emit('load-more')
    onLoadMore(): void {}
  }
</script>

<style lang="scss" scoped>
  .demo-loadmore-list {
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    overflow: auto;
    padding: 8px 24px;
    height: 300px;
    background-color: #fff;
  }
</style>
